#!/bin/bash
mysqladmin -h"192.168.60.200" -uzg -p"" extended-status -i1 2>/dev/null | awk 'BEGIN{local_switch=0;print "Date\t QPS Commit Rollback TPS Threads_con Threads_run Cache_miss\n------------------------------------------------------- "}
$2 ~ /Queries$/ {q=$4-lq;lq=$4;}
$2 ~ /Com_commit$/ {c=$4-lc;lc=$4;}
$2 ~ /Com_rollback$/ {r=$4-lr;lr=$4;}
$2 ~ /Innodb_buffer_pool_read_requests$/ {bt=$4;}
$2 ~ /Innodb_buffer_pool_reads$/ {bd=$4;}
$2 ~ /Threads_connected$/ {tc=$4;}
$2 ~ /Threads_running$/ {tr=$4;
if(local_switch==0)
    {local_switch=1; count=0}
else {
    if(count>10)
        {count=0;print "------------------------------------------------------- \nDate\t QPS Commit Rollback TPS Threads_con Threads_run Cache_miss\n------------------------------------------------------- ";}
    else{
        count+=1;
        printf "%s %-6d %-8d %-7d %-8d %-10d %-8d %d\n",  strftime("%H:%M:%S"),q,c,r,c+r,tc,tr, bd/bt * 100;
    }
}
}'
